package com.coolgor.coldot.dao.wechat.gzh;

import com.coolgor.coldot.entity.wechat.gzh.GZHUser;
import org.apache.ibatis.annotations.*;
import java.util.List;


@Mapper
public interface GZHUserDao {

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_wechat_gzh_user
			WHERE
				record_id = #{recordID}
		</script>
	""")
	@Results(id = "GZHUserMap", value = {
		@Result(property = "recordID", column = "record_id"),
		@Result(property = "appID", column = "app_id"),
		@Result(property = "openid", column = "openid"),
		@Result(property = "unionid", column = "unionid"),
		@Result(property = "userID", column = "user_id"),
		@Result(property = "nickname", column = "nickname"),
		@Result(property = "markname", column = "markname"),
		@Result(property = "sex", column = "sex"),
		@Result(property = "country", column = "country"),
		@Result(property = "province", column = "province"),
		@Result(property = "city", column = "city"),
		@Result(property = "headimgurl", column = "headimgurl"),
		@Result(property = "privilege", column = "privilege"),
		@Result(property = "status", column = "status"),
		@Result(property = "mobilephone", column = "mobilephone"),
		@Result(property = "email", column = "email"),
		@Result(property = "createTime", column = "create_time"),
		@Result(property = "lastEditTime", column = "last_edit_time"),
		@Result(property = "remark", column = "remark")
	})
	GZHUser queryByID(@Param("recordID") Long recordID);

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_wechat_gzh_user
			<where>
				<if test="gZHUserCondition.recordID != null">
					and record_id = #{gZHUserCondition.recordID}
				</if>
				<if test="gZHUserCondition.appID != null">
					and app_id like '${gZHUserCondition.appID}'
				</if>
				<if test="gZHUserCondition.openid != null">
					and openid like '${gZHUserCondition.openid}'
				</if>
				<if test="gZHUserCondition.unionid != null">
					and unionid like '${gZHUserCondition.unionid}'
				</if>
				<if test="gZHUserCondition.userID != null">
					and user_id like '${gZHUserCondition.userID}'
				</if>
				<if test="gZHUserCondition.nickname != null">
					and nickname like '${gZHUserCondition.nickname}'
				</if>
				<if test="gZHUserCondition.markname != null">
					and markname like '${gZHUserCondition.markname}'
				</if>
				<if test="gZHUserCondition.sex != null">
					and sex = #{gZHUserCondition.sex}
				</if>
				<if test="gZHUserCondition.country != null">
					and country like '${gZHUserCondition.country}'
				</if>
				<if test="gZHUserCondition.province != null">
					and province like '${gZHUserCondition.province}'
				</if>
				<if test="gZHUserCondition.city != null">
					and city like '${gZHUserCondition.city}'
				</if>
				<if test="gZHUserCondition.headimgurl != null">
					and headimgurl like '${gZHUserCondition.headimgurl}'
				</if>
				<if test="gZHUserCondition.privilege != null">
					and privilege like '${gZHUserCondition.privilege}'
				</if>
				<if test="gZHUserCondition.status != null">
					and status = #{gZHUserCondition.status}
				</if>
				<if test="gZHUserCondition.mobilephone != null">
					and mobilephone like '${gZHUserCondition.mobilephone}'
				</if>
				<if test="gZHUserCondition.email != null">
					and email like '${gZHUserCondition.email}'
				</if>
				<if test="gZHUserCondition.createTime != null">
					and create_time = #{gZHUserCondition.createTime}
				</if>
				<if test="gZHUserCondition.createTime != null">
					and <![CDATA[ create_time >= #{gZHUserCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.createTime != null">
					and <![CDATA[ create_time <= #{gZHUserCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.lastEditTime != null">
					and last_edit_time = #{gZHUserCondition.lastEditTime}
				</if>
				<if test="gZHUserCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time >= #{gZHUserCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time <= #{gZHUserCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.remark != null">
					and remark like '${gZHUserCondition.remark}'
				</if>
			</where>
			LIMIT #{rowIndex},#{pageSize};
		</script>
	""")
	@ResultMap("GZHUserMap")
	List<GZHUser> queryList(@Param("gZHUserCondition") GZHUser gZHUserCondition,
							@Param("rowIndex") int rowIndex,
							@Param("pageSize") int pageSize);

	@Select("""
		<script>
			SELECT
				count(1)
			FROM
				tb_coldot_wechat_gzh_user
			<where>
				<if test="gZHUserCondition.recordID != null">
					and record_id = #{gZHUserCondition.recordID}
				</if>
				<if test="gZHUserCondition.appID != null">
					and app_id like '${gZHUserCondition.appID}'
				</if>
				<if test="gZHUserCondition.openid != null">
					and openid like '${gZHUserCondition.openid}'
				</if>
				<if test="gZHUserCondition.unionid != null">
					and unionid like '${gZHUserCondition.unionid}'
				</if>
				<if test="gZHUserCondition.userID != null">
					and user_id like '${gZHUserCondition.userID}'
				</if>
				<if test="gZHUserCondition.nickname != null">
					and nickname like '${gZHUserCondition.nickname}'
				</if>
				<if test="gZHUserCondition.markname != null">
					and markname like '${gZHUserCondition.markname}'
				</if>
				<if test="gZHUserCondition.sex != null">
					and sex = #{gZHUserCondition.sex}
				</if>
				<if test="gZHUserCondition.country != null">
					and country like '${gZHUserCondition.country}'
				</if>
				<if test="gZHUserCondition.province != null">
					and province like '${gZHUserCondition.province}'
				</if>
				<if test="gZHUserCondition.city != null">
					and city like '${gZHUserCondition.city}'
				</if>
				<if test="gZHUserCondition.headimgurl != null">
					and headimgurl like '${gZHUserCondition.headimgurl}'
				</if>
				<if test="gZHUserCondition.privilege != null">
					and privilege like '${gZHUserCondition.privilege}'
				</if>
				<if test="gZHUserCondition.status != null">
					and status = #{gZHUserCondition.status}
				</if>
				<if test="gZHUserCondition.mobilephone != null">
					and mobilephone like '${gZHUserCondition.mobilephone}'
				</if>
				<if test="gZHUserCondition.email != null">
					and email like '${gZHUserCondition.email}'
				</if>
				<if test="gZHUserCondition.createTime != null">
					and create_time = #{gZHUserCondition.createTime}
				</if>
				<if test="gZHUserCondition.createTime != null">
					and <![CDATA[ create_time >= #{gZHUserCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.createTime != null">
					and <![CDATA[ create_time <= #{gZHUserCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.lastEditTime != null">
					and last_edit_time = #{gZHUserCondition.lastEditTime}
				</if>
				<if test="gZHUserCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time >= #{gZHUserCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time <= #{gZHUserCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="gZHUserCondition.remark != null">
					and remark like '${gZHUserCondition.remark}'
				</if>
			</where>
		</script>
	""")
	int queryCount(@Param("gZHUserCondition") GZHUser gZHUserCondition);

	@Insert("""
		<script>
			INSERT INTO tb_coldot_wechat_gzh_user (
				app_id,
				openid,
				unionid,
				user_id,
				nickname,
				markname,
				sex,
				country,
				province,
				city,
				headimgurl,
				privilege,
				status,
				mobilephone,
				email,
				create_time,
				last_edit_time,
				remark
			) VALUES (
				#{appID},
				#{openid},
				#{unionid},
				#{userID},
				#{nickname},
				#{markname},
				#{sex},
				#{country},
				#{province},
				#{city},
				#{headimgurl},
				#{privilege},
				#{status},
				#{mobilephone},
				#{email},
				#{createTime},
				#{lastEditTime},
				#{remark}
			)
		</script>
	""")
	@Options(useGeneratedKeys = true, keyColumn = "record_id", keyProperty = "recordID")
	int insert(GZHUser gZHUser);

	@Update("""
		<script>
			UPDATE tb_coldot_wechat_gzh_user
			<set>
				<if test="appID != null">app_id=#{appID},</if>
				<if test="openid != null">openid=#{openid},</if>
				<if test="unionid != null">unionid=#{unionid},</if>
				<if test="userID != null">user_id=#{userID},</if>
				<if test="nickname != null">nickname=#{nickname},</if>
				<if test="markname != null">markname=#{markname},</if>
				<if test="sex != null">sex=#{sex},</if>
				<if test="country != null">country=#{country},</if>
				<if test="province != null">province=#{province},</if>
				<if test="city != null">city=#{city},</if>
				<if test="headimgurl != null">headimgurl=#{headimgurl},</if>
				<if test="privilege != null">privilege=#{privilege},</if>
				<if test="status != null">status=#{status},</if>
				<if test="mobilephone != null">mobilephone=#{mobilephone},</if>
				<if test="email != null">email=#{email},</if>
				<if test="createTime != null">create_time=#{createTime},</if>
				<if test="lastEditTime != null">last_edit_time=#{lastEditTime},</if>
				<if test="remark != null">remark=#{remark}</if>
			</set>
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int update(GZHUser gZHUser);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_wechat_gzh_user
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int delete(Long recordID);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_wechat_gzh_user
			WHERE
				record_id IN
				<foreach collection="list" item="recordID" open="(" separator="," close=")">
					#{recordID}
				</foreach>
		</script>
	""")
	int deleteBatch(List<Long> idList);

}